﻿using System;
using System.ComponentModel;

using SharpGL.Media3D;

namespace SharpGL.SceneGraph.Primitives.SmartAxies
{
    [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class AxisLabels : AxisCaption2D
    {
        #region Private Fields

        private static string defaultFormat = "g";

        private string format = defaultFormat;
        private float separation = 0.01f;

        #endregion Private Fields

        #region Public Constructors

        public AxisLabels()
        {
        }

        #endregion Public Constructors

        #region Internal Methods

        internal void Render(OpenGL gl, Point3D position, float value)
        {
            if (!OpenGL.IsValidContext(gl))
                throw new ArgumentException();

            if (Visible)
            {
                gl.Color(Color);
                TextObject.Position = position;
                TextObject.Text = value.ToString(format);
                TextObject.Render(gl, RenderMode.Render);
            }
        }

        #endregion Internal Methods

        #region Public Properties

        [Description("Format"), Category("Axis labels")]
        public string Format
        {
            get { return format; }
            set
            {
                if (format != value)
                {
                    if (string.IsNullOrWhiteSpace(value))
                        format = defaultFormat;
                    else
                        format = value;

                    NotifyPropertyChanged("Format");
                }
            }
        }

        [Description("Separation"), Category("Axis labels")]
        public float Separation
        {
            get { return separation; }
            set
            {
                if (separation != value)
                {
                    separation = value;

                    NotifyPropertyChanged("Separation");
                }
            }
        }

        #endregion Public Properties
    }
}
